package com.twu.biblioteca.ui;

import com.twu.biblioteca.data.Book;
import com.twu.biblioteca.data.BookDAO;
import com.twu.biblioteca.exceptions.BookAlreadyCheckedOutException;

/**
 * Created by florian on 27/12/13.
 */
public class CheckoutController extends ControllerWithBook {
    public CheckoutController(ScreenControllerFactory controllerFactory, BibliotecaUI ui, BookDAO bookDAO) {
        super(controllerFactory, ui, bookDAO);

    }

    @Override
    protected void showUsage() {
        ui.showCheckoutMessage();
    }

    @Override
    protected ScreenController handleWithBook(Book book) throws BookAlreadyCheckedOutException {
        bookDAO.checkoutBook(book);
        ui.showSuccessfulCheckoutMessage();
        return controllerFactory.createMainScreenController();
    }
    @Override
    protected ScreenController handleError() {
        ui.showUnsuccessfulCheckoutMessage();
        return this;
    }
}
